/*
CREATE TABLE huesped
(
  huesid serial NOT NULL,
  hueapa character varying(50),
  hueama character varying(50),
  huenom character varying(50),
  huefon character varying(12),
  huemai character varying(50)
) 
 */

package solucionessgh.Reserva;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import solucionessgh.Util.DataBase;

/**
 *
 * @author roderick
 */
public class HuespedModel extends DataBase{

    private int huesid;
    private String hueapa;
    private String hueama;
    private String huenom;
    private String huefon;
    private String huemai;

    public HuespedModel(){

    }

    private boolean validar(){
        return true;
    }

    public boolean create(){
        if(validar()){
            try{
                Connection con = ConnectionBase();
                PreparedStatement stmt = con.prepareStatement("INSERT INTO huesped(hueapa, hueama, huenom, huefon, huemai)VALUES (?, ?, ?, ?, ?);");
                stmt.setString(1,this.hueapa);
                stmt.setString(2,this.hueama);
                stmt.setString(3,this.huenom);
                stmt.setString(4,this.huefon);
                stmt.setString(5,this.huemai);
                stmt.executeUpdate();
                return true;
            }
            catch( Exception e ){
                JOptionPane.showMessageDialog(null,
                    e.getMessage(),
                    "Huesped",
                    JOptionPane.ERROR_MESSAGE);
            }
        }
        return false;
    }

    public boolean update(){
        //if(validar()){
            try{
                Connection con = ConnectionBase();
                PreparedStatement stmt = con.prepareStatement("UPDATE huesped  SET hueapa=?, hueama=?, huenom=?, huefon=?, huemai=? where huesid=? ;");
                stmt.setString(1,this.hueapa);
                stmt.setString(2,this.hueama);
                stmt.setString(3,this.huenom);
                stmt.setString(4,this.huefon);
                stmt.setString(5,this.huemai);
                stmt.setInt(6, huesid);
                stmt.executeUpdate();
                return true;
            }
            catch( Exception e ){
                JOptionPane.showMessageDialog(null,
                    e.getMessage(),
                    "Nivel Usuario",
                    JOptionPane.ERROR_MESSAGE);
            }
        //}
        return false;
    }

    public boolean delete(){
        //if(validar()){
            try{
                Connection con = ConnectionBase();
                PreparedStatement stmt = con.prepareStatement("delete from huesped where huesid=?;");
                stmt.setInt(1, huesid);
                stmt.executeUpdate();
                return true;
            }
            catch( Exception e ){
                JOptionPane.showMessageDialog(null,
                    e.getMessage(),
                    "Nivel Usuario",
                    JOptionPane.ERROR_MESSAGE);
            }
        //}
        return false;
    }

    public ResultSet read(){
        return this.find("SELECT huesid, hueapa, hueama, huenom, huefon, huemai FROM huesped order by hueapa ");
    }


    public ResultSet finder(String var){
        return this.find("SELECT huesid, hueapa, hueama, huenom, huefon, huemai FROM huesped WHERE hueapa LIKE '"+var+"%';");
    }

    public ResultSet finder(int var){
        return this.find("SELECT huesid, hueapa, hueama, huenom, huefon, huemai FROM huesped WHERE huesid = "+var+";");
    }


    public String getHueama() {
        return hueama;
    }

    public void setHueama(String hueama) {
        this.hueama = hueama;
    }

    public String getHueapa() {
        return hueapa;
    }

    public void setHueapa(String hueapa) {
        this.hueapa = hueapa;
    }

    public String getHuefon() {
        return huefon;
    }

    public void setHuefon(String huefon) {
        this.huefon = huefon;
    }

    public String getHuemai() {
        return huemai;
    }

    public void setHuemai(String huemai) {
        this.huemai = huemai;
    }

    public String getHuenom() {
        return huenom;
    }

    public void setHuenom(String huenom) {
        this.huenom = huenom;
    }

    public int getHuesid() {
        return huesid;
    }

    public void setHuesid(int huesid) {
        this.huesid = huesid;
    }
}
